package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.NiuBee;
import yxy.cherry.battle.module.affix.AffixFactory.SkillTypeEnum;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_12_伤害反弹;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

/** 受伤反弹 */
@SkillType(Type = SkillTypeEnum.受伤反弹)
public class Affix_11_受伤反弹 extends Skill {

	private int get反弹比例() {
		return getParam(0);
	}

	public Affix_11_受伤反弹(Fighter actor, skill skilldata, int probability, int[] params) {
		super(actor, skilldata, probability, params);
	}

	private RecordStreamGroup steamGroup;

	@Override
	public RecordStreamGroup record() {
		steamGroup = getRecord().stream(new RecordStreamGroup());
		steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
		return steamGroup;
	}

	@Override
	public boolean exec(Fighter actor, Fighter target) {
		if (getAffixContext().is附加行动中()) {
			return false;
		}
		if (target instanceof NiuBee) {
			return false;
		}
		if (!actor.is活着()) {
			return false;
		}
		long 总伤害 = getAffixContext().get攻击行动().getTarget(actor).总伤害();
		if (总伤害 <= 0) {
			return false;
		}
		long 反弹伤害 = 总伤害 * get反弹比例() / VALUE_比率分母;

		target.set伤害(反弹伤害);
		steamGroup.add(new RecordStream_12_伤害反弹(actor, target, 反弹伤害)).record();

		// 流脚本

		if (!target.is活着()) {
			target.handle本方有死将();
		}

		Battle.battleLogger(6,"受伤反弹：反弹者："+actor.getName() + "对" +"总伤害："+总伤害+"反弹比例："+get反弹比例()+"目标："+ target.getName()+"反弹伤害："+反弹伤害);
		// 统计
		getRecord().get统计().getFighter(actor.getFighterPosition()).addDMG(反弹伤害);
		getRecord().get统计().getFighter(target.getFighterPosition()).addHUT(反弹伤害);

		return true;
	}
}